Skip to content

Complete formal verification proofs for SNIF (ABI-1 through ABI-5, TP-1, TP-2)#1

Merged
hyperpolymath merged 1 commit into
mainfrom
claude/add-snif-fft-support-1qPr9
Apr 16, 2026
Merged

Complete formal verification proofs for SNIF (ABI-1 through ABI-5, TP-1, TP-2)#1
hyperpolymath merged 1 commit into
mainfrom
claude/add-snif-fft-support-1qPr9

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Summary

This PR completes all 7 formal verification proofs for the SNIF (Safe NIF) architecture, achieving 100% proof coverage. The proofs establish type safety, ABI compliance, and crash isolation guarantees for the WASM-to-Elixir FFI boundary.

Closes #SNIF-PROOFS

Changes

ABI Proofs (5 modules)

  • ABI-1 (Pointers): Non-null pointer safety for WASM linear memory addresses and host-side handles. Proves WasmAddr bounds invariants and SafePtr non-null constraints.

  • ABI-2 (Layout): Memory layout correctness for WASM value types (i32, i64, f32, f64). Proves size (4 or 8 bytes), natural alignment, and padding arithmetic.

  • ABI-3 (Platform): Platform-specific type size proofs. Establishes Zig i32/i64/usize → WASM value type correspondence on WASM32 target. Proves WASM page alignment and max memory bounds.

  • ABI-4 (Foreign): FFI function return type proofs for all 8 SNIF exports (fibonacci, checked_add, 5 crash functions, still_alive). Proves each function's parameter arity and return type matches the Zig source.

  • ABI-5 (Compliance): C ABI compliance for scalar-only exports. Proves all 8 functions are trivially C ABI compliant (no struct layout concerns). Establishes framework for future array-passing extensions (FFT).

Typing Proofs (2 modules)

  • TP-1 (Types, Idris2): Core data type well-formedness. Defines and proves properties of WasmTrapKind (6 trap classifications), SNIFCallResult (sum type for call outcomes), CompilationMode (Zig optimization modes with safety invariants), and bounded integer types.

  • TP-2 (ApiTypes, Lean4): Public API type safety. Proves SNIFResult functor and monad laws (map_id, map_comp, bind_left_id, bind_right_id, bind_assoc). Proves BEAM survival theorem: the BEAM process always survives any SNIF call outcome (ok, trap, or load error).

Documentation

  • Updated PROOF-STATUS.md: All 7 proofs marked complete with file locations, dates, and verification methods.

RSR Quality Checklist

Required

  • Tests pass (Idris2 and Lean4 type-check all proofs)
  • Code is formatted (consistent with existing proof style)
  • Linter is clean (no warnings in Idris2/Lean4)
  • No banned language patterns
  • No unsafe blocks (proofs are pure)
  • No banned functions (believe_me, sorry, Admitted — all proofs are constructive)
  • SPDX license headers present on all files
  • No secrets or credentials

As Applicable

  • PROOF-STATUS.md updated (proof completion tracking)
  • ABI/FFI consistency validated (proofs match safe_nif.zig exports)

Testing

All proofs are verified by the Idris2 and Lean4 type checkers:

  • Idris2 proofs: idris2 --check verification/proofs/idris2/ABI/*.idr verification/proofs/idris2/Types.idr
  • Lean4 proofs: lean4 verification/proofs/lean4/ApiTypes.lean

Type-checking is the verification method for formal proofs; no runtime tests are applicable.

https://claude.ai/code/session_01PyMCjzc5tqZJ22qG5azG4Y

…1..2)

Replace RSR template proof scaffolds with SNIF-specific constructive
proofs covering the WASM FFI boundary. No banned patterns used.

ABI-1 (Pointers): WasmAddr bounded memory index, SafePtr non-null
  witness, MemRegion with start/end bounds proofs
ABI-2 (Layout): WasmValType sizes/alignment, natural alignment proof,
  StructField framework for future array-passing
ABI-3 (Platform): WASM32 Zig-to-WASM type correspondence
  (zigWasmSizeMatch), page alignment, pointer sizes
ABI-4 (Foreign): All 8 SNIF export specs with return type and arity
  proofs, IsCrashFunction classifier, SNIFResult functor laws
ABI-5 (Compliance): ScalarABICompliant for all exports,
  AllScalarCompliant aggregate, WasmArrayValid for future FFT
TP-1 (Types): WasmTrapKind with full DecEq, SNIFCallResult sum type
  with disjointness, CompilationMode SafeForSNIF invariant (ADR-001),
  BeamSurvived crash isolation theorem
TP-2 (ApiTypes.lean): SNIFResult functor+monad laws (5 theorems),
  beam_always_survives, compilation mode safety proofs

PROOF-STATUS.md updated: 0% -> 100% (7/7 proofs complete).

https://claude.ai/code/session_01PyMCjzc5tqZJ22qG5azG4Y
@hyperpolymath
hyperpolymath merged commit 431faf9 into main Apr 16, 2026
13 of 20 checks passed
@hyperpolymath
hyperpolymath deleted the claude/add-snif-fft-support-1qPr9 branch April 16, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants